<% unless time_log.nil? %>
    <td class="checkbox hide-when-print"><%= check_box_tag("ids[]", time_log.id, false, :id => nil) %></td>
    <td class="tt_log_date"><%= time_log.tt_log_date %></td>
    <td colspan=4>
      <% prefix = "time_log_add_booking[]" %>
      <%= fields_for prefix, time_log do |f| %>
          <%= f.hidden_field(:id) %>

          <% projects = User.current.memberships.collect(&:project).compact.uniq %>
          <% time_log.project_id.nil? ? select = nil : select = Project.find(time_log.project_id) %>
          <% proj_list = "<option value=''>#{ l(:time_tracker_label_none) }</option>" %>
          <% proj_list << "<option value='' disabled='disabled'>---</option>" %>
          <% proj_list = proj_list.html_safe %>
          <% proj_list << project_tree_options_for_select(projects, :selected => select) %>
          <div class="task_form_sub_fields">
            <div class="input_hint"><%= l(:time_tracker_label_project) %></div>
            <div class="task_form_input">
              <%= select_tag "time_log_add_booking_#{time_log.id}_project_id_select", proj_list, :onchange => "$('#time_log_add_booking_#{time_log.id}_project_id').val(this.value); validate_list_inputs('time_log_add_booking_#{time_log.id}'); updateBookingActivity('#{User.current.api_key}', 'time_log_add_booking_#{time_log.id}')" %>
            </div>
            <%= f.hidden_field :project_id %>
          </div>

          <div class="task_form_sub_fields">
            <div class="input_hint"><%= l(:time_tracker_label_activity) %></div>
            <div class="task_form_input">
              <% activities = get_activities time_log.project_id %>
              <%= select_tag "time_log_add_booking_#{time_log.id}_activity_id_select",options_from_collection_for_select(activities, :id, :name), :onchange => "validate_list_inputs('time_log_add_booking_#{time_log.id}');", :name=> "time_log_add_booking[#{time_log.id}][activity_id]", :include_blank => true%>
            </div>
          </div>

          <div class="task_form_sub_fields">
            <div class="input_hint"><%= l(:time_tracker_label_issue) %></div>
            <div class="task_form_input"><%= f.text_field :issue_id, :size => "15", :placeholder => "issue", :onchange => "updateBookingProject('#{User.current.api_key}', 'time_log_add_booking_#{time_log.id}')" %></div>
          </div>

          <div class="task_form_sub_fields">
            <div class="input_hint"><%= l(:time_tracker_label_comments) %></div>
            <div class="task_form_input"><%= f.text_field :comments, :size => 30, :maxlength => 255 %></div>
          </div>

          <div class="task_form_sub_fields">
            <div class="input_hint"><%= l(:time_tracker_label_start_time) + " (min: #{time_log.get_formatted_start_time})" %></div>
            <div class="task_form_input">
              <%= hidden_field_tag "time_log_add_booking_#{time_log.id}_min_time", time_log.get_formatted_start_time %>
              <%= f.text_field :start_time, :value => time_log.get_formatted_start_time, :size => "10", :placeholder => "start", :onchange => "updateBookingHours('time_log_add_booking_#{time_log.id}')" %>
            </div>
          </div>

          <div class="task_form_sub_fields">
            <div class="input_hint"><%= l(:time_tracker_label_stop_time) + " (max: #{time_log.get_formatted_stop_time})" %></div>
            <div class="task_form_input">
              <%= hidden_field_tag "time_log_add_booking_#{time_log.id}_max_time", time_log.get_formatted_stop_time %>
              <%= f.text_field :stop_time, :value => time_log.get_formatted_stop_time, :size => "10", :placeholder => "stop", :onchange => "updateBookingHours('time_log_add_booking_#{time_log.id}')" %>
            </div>
          </div>

          <div class="task_form_sub_fields">
            <div class="input_hint"><%= l(:time_tracker_label_time_spent) + " (max: #{time_log.get_formatted_bookable_hours})" %></div>
            <div class="task_form_input">
              <%= hidden_field_tag "time_log_add_booking_#{time_log.id}_max_spent_time", time_log.get_formatted_bookable_hours %>
              <%= f.text_field :spent_time, :value => time_log.get_formatted_bookable_hours, :size => "12", :placeholder => "spent time", :onchange => "updateBookingStop('time_log_add_booking_#{time_log.id}')" %>
            </div>
          </div>

          <%= f.submit l(:time_tracker_label_book), :class => "tl_book_form_button" %>
          <%= link_to l(:button_cancel), {:controller => 'time_logs', :action => 'get_list_entry', :time_log_id => time_log.id}, :remote => true %>
      <% end %>
      <%= javascript_tag render :partial => 'booking_form_autocomplete', :locals => {:key => User.current.api_key, :time_log => time_log} %>
    </td>

    <%= javascript_tag do %>
        var cols = $("#entry-<%= time_log.id %>").parents('form:first').find('thead > tr > th').length;
        var myTD = $("#entry-<%= time_log.id %> > td")[2];
        myTD.setAttribute('colspan', cols - 2);
    <% end %>
<% end %>
